# -*- coding: utf-8 -*-
"""
Created on Tue Jan  4 15:19:47 2022

@author: saw
"""

import numpy as np
class Radar:
    #雷达扫描半径，初始时认为处处无障碍，每次移动刷新地图   
    def __init__(self,radar_R,realmap):
        self.w=np.shape(realmap)[1]
        self.h=np.shape(realmap)[0]
        self.R=radar_R
        knowmap=np.zeros([self.w,self.h])
    #判断点是否在雷达范围内
    def instance(self,a,b,c,d):
        if (a-c)*(a-c)+(b-d)*(b-d)<self.R*self.R:
            return True
        
    #雷达扫描，扫描的点不出边界，不出雷达半径，返回更新后的地图用于Astar    
    def searchfun(self,point,Maplist,Maplist_):
        knowmap=Maplist_.data
        i_min=max(point.x-self.R,0)
        i_max=min(point.x+self.R,self.w)
        j_min=max(point.y-self.R,0)
        j_max=min(point.y+self.R,self.h)
        for i in range(i_min,i_max):
            for j in range(j_min,j_max):
                if self.instance(i,j,point.x,point.y):
                    knowmap[i][j]=Maplist.data[i][j]
        return knowmap